unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  IS_INITIALIZE         = WM_USER + 4;
  UN_INITIALIZE         = WM_USER + 6;

type
  TForm1 = class(TForm)
    Btnx_1: TButton;
    Btnx_2: TButton;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
  private
    FWorkStat:Boolean;
  public
    procedure CheckItem01;
    procedure CheckItem02;

    procedure CheckItem03;
    procedure CheckItem04;

    procedure IsInitialize(var Message: TMessage); message IS_INITIALIZE;
    procedure UNInitialize(var Message: TMessage); message UN_INITIALIZE;    
  end;

var
  Form1: TForm1;


    

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.CheckItem01;
begin
  ShowMessage('i am checkitem1.');
  Sleep(5* 1000);
  Application.ProcessMessages;  
  FWorkStat:=True;
end;

procedure TForm1.CheckItem02;
begin
  ShowMessage('i am checkitem2.');
end;

procedure TForm1.Btnx_1Click(Sender: TObject);
begin
  FWorkStat:=False;
  while not FWorkStat do
  begin
    CheckItem01;
  end;

  CheckItem02;
end;

procedure TForm1.CheckItem03;
begin
  ShowMessage('i am checkitem1.');
  Sleep(5* 1000);
  Application.ProcessMessages;
  FWorkStat:=True;

  PostMessage(Handle,IS_INITIALIZE,0,0);
end;

procedure TForm1.CheckItem04;
begin
  ShowMessage('i am checkitem04.');
end;

procedure TForm1.IsInitialize(var Message: TMessage);
begin
  CheckItem04;
end;

procedure TForm1.UNInitialize(var Message: TMessage);
begin

end;

procedure TForm1.Btnx_2Click(Sender: TObject);
begin
  CheckItem03;
end;

end.
